package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 负责与dubbo服务进行交互
 * @author 陈功炳
 * @since 2021/11/25 20:43
 */
@Service
public class RecommendUserService {
    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;
    /**
     * 去mongoDB里查今日佳人的id和缘分值
     * @param id
     * @return
     */
    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        if (recommendUser == null){
            return null;
        }
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        //缘分值
        double socre = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(socre).longValue());//取整,98.2 -> 98
        return todayBest;
    }


    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        return recommendUserApi.queryPageInfo(id,page,pagesize);
    }

    /**
     * 查询推荐好友的缘分值
     *
     * @param userId
     * @param toUserId
     * @return
     */
    public Double queryScore(Long userId, Long toUserId){
        Double score = this.recommendUserApi.queryScore(userId, toUserId);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        //默认值
        return 98d;
    }


    /**
     * 查询探花卡片列表
     * @param userId
     * @param count
     * @return
     */
    public List<RecommendUser> queryCardList(Long userId, Integer count) {
        return this.recommendUserApi.queryCardList(userId, count);
    }
}
